package com.sky.controller.user;

import com.sky.constant.StatusConstant;
import com.sky.context.BaseContext;
import com.sky.entity.AddressBook;
import com.sky.entity.Setmeal;
import com.sky.result.Result;
import com.sky.service.AddressBookService;
import com.sky.service.SetmealService;
import com.sky.vo.DishItemVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;
// import springfox.documentation.annotations.Cacheable;

import java.util.List;

@Slf4j
@Api(tags = "用户端套餐接口")
@RestController("userSetmealController")
@RequestMapping("/user/setmeal")

public class SetmealController {
    @Autowired
    private SetmealService setmealService;

    /**
     * 根据分类查询套餐
     * @param categoryId
     * @return
     */
    @Cacheable(cacheNames = "setmeal", key="#categoryId")
    @RequestMapping("/list")
    public Result<List<Setmeal>> list(Long categoryId) {
        log.info("用户端-根据分类查询套餐：{}", categoryId);
        List<Setmeal> setmeales = setmealService.list(categoryId, StatusConstant.ENABLE);

        return Result.success(setmeales);
    }

    /**
     * 根据套餐id查询菜品概要
     * @param id
     * @return
     */
    @GetMapping("/dish/{id}")
    public Result<List<DishItemVO>>listDishItem(@PathVariable Long id) {
        log.info("用户端-根据套餐id查询菜品：{}", id);
        List<DishItemVO> dishItemVOS = setmealService.getDishItemById(id);
        return Result.success(dishItemVOS);
    }

}
